package com.ruoyi.project.viewin.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.viewin.domain.ViewInJobDetail;
import com.ruoyi.project.viewin.service.IViewInJobDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库子明细Controller
 * 
 * @author ruoyi
 * @date 2023-04-13
 */
@Controller
@RequestMapping("/viewin/detail")
public class ViewInJobDetailController extends BaseController
{
    private String prefix = "viewin/detail";

    @Autowired
    private IViewInJobDetailService viewInJobDetailService;

    @GetMapping()
    public String detail()
    {
        return prefix + "/detail";
    }

    /**
     * 查询入库子明细列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewInJobDetail viewInJobDetail)
    {
        startPage();
        List<ViewInJobDetail> list = viewInJobDetailService.selectViewInJobDetailList(viewInJobDetail);
        return getDataTable(list);
    }

    /**
     * 导出入库子明细列表
     */
    @Log(title = "入库子明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewInJobDetail viewInJobDetail)
    {
        List<ViewInJobDetail> list = viewInJobDetailService.selectViewInJobDetailList(viewInJobDetail);
        ExcelUtil<ViewInJobDetail> util = new ExcelUtil<ViewInJobDetail>(ViewInJobDetail.class);
        return util.exportExcel(list, "入库子明细数据");
    }

    /**
     * 新增入库子明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存入库子明细
     */
    @Log(title = "入库子明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewInJobDetail viewInJobDetail)
    {
        return toAjax(viewInJobDetailService.insertViewInJobDetail(viewInJobDetail));
    }

    /**
     * 修改入库子明细
     */
    @GetMapping("/edit/{taskNo}")
    public String edit(@PathVariable("taskNo") String taskNo, ModelMap mmap)
    {
        ViewInJobDetail viewInJobDetail = viewInJobDetailService.selectViewInJobDetailByTaskNo(taskNo);
        mmap.put("viewInJobDetail", viewInJobDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存入库子明细
     */
    @Log(title = "入库子明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewInJobDetail viewInJobDetail)
    {
        return toAjax(viewInJobDetailService.updateViewInJobDetail(viewInJobDetail));
    }

    /**
     * 删除入库子明细
     */
    @Log(title = "入库子明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewInJobDetailService.deleteViewInJobDetailByTaskNos(ids));
    }
}
